package com.rjxy.plansystemmanagement.controller.entityController;

import com.rjxy.plansystemmanagement.entity.ChargebacksInformation;
import com.rjxy.plansystemmanagement.entity.FlightInformation;
import com.rjxy.plansystemmanagement.entity.Result.Result;
import com.rjxy.plansystemmanagement.service.ChargebacksService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/Chargebacks")
public class ChargebacksController {
    @Autowired
    private ChargebacksService chargebacksService;

    /**
     * 查询所有退单信息
     * @return
     */
    @GetMapping
    public Result list(){
        log.info("查询所有退单信息");
        List<ChargebacksInformation> chargebacksInformationList = chargebacksService.list();
        return Result.success(chargebacksInformationList);
    }

    /**
     * 根据id删除指定退单信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteChargeback(@PathVariable Integer id){
        log.info("根据id{id}删除指定退单信息",id);
        chargebacksService.deleteChargeback(id);
        return Result.success();
    }

    /**
     * 添加退单信息
     * @param chargebacksInformation
     * @return
     */
    @PostMapping
    public Result addChargeback(@RequestBody ChargebacksInformation chargebacksInformation){
        log.info("添加退单");
        chargebacksService.addChargeback(chargebacksInformation);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getChargebackById(@PathVariable Integer id){
        log.info("获取指定ID的{}退单",id);
        ChargebacksInformation chargebacksInformation = chargebacksService.getChargebackById(id);
        return Result.success(chargebacksInformation);
    }

}
